//
//  HYHomeBaseListCell.m
//  XPlayer
//
//  Created by liguoqing on 2023/9/8.
//

#import "HYHomeBaseListCell.h"

@implementation HYHomeBaseListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = [CommUtls dynamicColorWithLightModeHex:@"#FFFFFF" darkModeHex:@"#181A22"];
        [self configUI];
    }
    return self;
}

- (void)configUI
{
    [self.contentView addSubview:self.backView];
    [self.backView addSubview:self.setBtn];
    [self.setBtn sizeToFit];
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(2.5);
        make.left.mas_equalTo(5);
        make.right.mas_equalTo(-5);
        make.bottom.mas_equalTo(-2.5);
    }];
    [self.setBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.right.equalTo(self.backView);
        make.width.mas_equalTo(44);
    }];
}

- (void)bindViewModel:(HYHomeFileItemViewModel *)vm
{
    _itemVm = vm;
    self.titleLabel.text = vm.fileName;
    self.setBtn.hidden = vm.isHiddenSet;
}

- (void)setBtnAction
{
    [self.itemVm.setSubject sendNext:self.itemVm];
}

#pragma mark - loadLazy
- (UIView *)backView
{
    if(!_backView){
        _backView = [[UIView alloc]init];
        _backView.backgroundColor = AppContentBgThemeColor;
        _backView.layer.cornerRadius = 4.0;
        _backView.layer.masksToBounds = YES;
    }
    return _backView;
}

- (UIImageView *)iconView
{
    if(!_iconView){
        _iconView = [[UIImageView alloc]init];
        _iconView.image =  [UIImage imageNamed:@"icon_lock"];
    }
    return _iconView;
}

- (UIImageView *)coverView
{
    if(!_coverView){
        _coverView = [[UIImageView alloc]init];
        _coverView.layer.cornerRadius = 4.0;
        _coverView.layer.masksToBounds = YES;
    }
    return _coverView;
}

- (UILabel *)titleLabel
{
    if(!_titleLabel){
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.font = kIsIPad?FONT_BOLD_SIZE(16):FONT_BOLD_SIZE(14);
        _titleLabel.numberOfLines = 2;
        _titleLabel.lineBreakMode = NSLineBreakByCharWrapping;
        _titleLabel.textColor = APPTextThemeColor;
    }
    return _titleLabel;
}

- (UILabel *)dateLabel
{
    if(!_dateLabel){
        _dateLabel = [[UILabel alloc]init];
        _dateLabel.textColor = UIColor.systemGrayColor;
        _dateLabel.font = kIsIPad?FONT_SIZE(14):FONT_SIZE(12);
    }
    return _dateLabel;
}

- (UILabel *)countLabel
{
    if(!_countLabel){
        _countLabel = [[UILabel alloc]init];
        _countLabel.font = kIsIPad?FONT_SIZE(14):FONT_SIZE(12);
        _countLabel.textColor = APPTextThemeColor;
    }
    return _countLabel;
}

- (UIButton *)setBtn
{
    if(!_setBtn){
        _setBtn = [[UIButton alloc]init];
        [_setBtn setImage:[UIImage imageNamed:@"icon_list_more"] forState:UIControlStateNormal];
        [_setBtn addTarget:self action:@selector(setBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _setBtn;
}


@end
